package com.supermap.qdsearch.fragment;


import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.supermap.qdsearch.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * A simple {@link Fragment} subclass.
 */
public class SyncFragment extends Fragment {


    Unbinder unbinder;

    @BindView(R.id.tv_task_download)
    TextView tvTaskDownload;
    @BindView(R.id.tv_task_upload)
    TextView tvTaskUpload;
    @BindView(R.id.tv_download_map)
    TextView tvDownloadMap;
    @BindView(R.id.tv_sync_database)
    TextView tvSyncDatabase;
    @BindView(R.id.iv_load)
    ImageView ivLoad;
    @BindView(R.id.tv_load)
    TextView tvLoad;
    @BindView(R.id.rl_load)
    RelativeLayout rlLoad;
    private AnimationDrawable drawable;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_sync, container, false);
        unbinder = ButterKnife.bind(this, view);

        drawable = (AnimationDrawable) ivLoad.getDrawable();
        return view;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick({R.id.tv_sync_database, R.id.tv_task_download, R.id.tv_task_upload, R.id.tv_download_map})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_sync_database:
                showWaitPanel("基础数据正在下载");
                break;
            case R.id.tv_task_download:
                showWaitPanel("任务数据正在下载");
                break;
            case R.id.tv_task_upload:
                showWaitPanel("任务数据正在上传");
                break;
            case R.id.tv_download_map:
                showWaitPanel("地图数据正在下载");
                break;
        }
    }


    /**
     * 打开等待层
     *
     * @param msg
     */
    public void showWaitPanel(final String msg) {
        drawable.start();
        tvLoad.setText(msg);
        rlLoad.setVisibility(View.VISIBLE);
    }

    /**
     * 关闭等待层
     */
    public void closeWaitPanel() {
        drawable.stop();
        rlLoad.setVisibility(View.GONE);
    }
}
